package com.tianqu.tms.www.transfer.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.www.transfer.controller.TransferRgAdvanceInputResultController;
import com.tianqu.tms.www.transfer.viewhelper.TransferRgAdvanceInputViewHelper;
/**
 * 
 * 进入待办受理录入结果页面Action
 * 
 * @author Administrator
 *
 */
public class TransferRgAdvanceInputResultAction extends TmsAction {
	private Logger logger = Logger.getLogger(TransferRgAdvanceInputResultAction.class);
		
	private static final String SYSPATH = "sysPath";
	
	private static final String LEFTLINE ="/";
	
	private static final String TMSPATH = "/tmsweb";
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		
		TransferRgAdvanceInputViewHelper view = (TransferRgAdvanceInputViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
		TransferAcceptedInfo accept = new TransferAcceptedInfo();
		accept = accept.findTransStatusBySerial(view.getSerial());
		if (accept != null) {
			if(accept.getMaterialImages1()!=null && !"".equals(accept.getMaterialImages1()))
			{
				view.setMaterialImages1(accept.getMaterialImages1());
				view.setMaterialImages2(accept.getMaterialImages2());
				view.setMaterialImages3(accept.getMaterialImages3());
				view.setMaterialImages4(accept.getMaterialImages4());
				view.setMaterialImages5(accept.getMaterialImages5());						
			}else{
				setErrorsToRequest(request, TmsConstants.IM007, null);
				return mapping.getInputForward();
			}
		} else {
			setErrorsToRequest(request, TmsConstants.IM007, null);
			return mapping.getInputForward();
		}

		isToken(mapping, request);
		
		TransferRgAdvanceInputResultController controller = new TransferRgAdvanceInputResultController();
		String sysPath = request.getSession().getServletContext().getRealPath(LEFTLINE).replace(TMSPATH, TmsConstants.BLANK);
		uc.setAttribute(SYSPATH, sysPath);
		controller.execute(uc);
		
		uc.removeAttribute(TmsConstants.VIEWHELP);
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
